% construct diffusion and random force part
function rest = randomtest(t,y,para,casenum)

load('alphas');
load('betas');
load('msval');
load('sigma');

num=para(1);alphaK=para(2);
dt1=0.5/num; 
t2index=floor((t+0.5*dt1)/dt1)+1;
switch casenum
    case 1
        betarow=size(betas,1);
        row=betarow;
        if row >=2
            rest(row)=0;
        end
        rest(1)=t;
        rest(2:k+1)=0;%sum(nsval(t2index,1:k).*msval(t2index,1:k));
        rest(k+2:2*k+1)=sqrt(2)*nsval(t2index,1:k)...
            .*msval(t2index,1:k);
        for ii=2*k+2:row
            k=find(betas(ii,:)==1);
            rest(ii)=2*msval(t2index,k(1))*nsval(t2index,k(2))+...
                2*msval(t2index,k(2))*nsval(t2index,k(1));
        end
    case 5
        alpharow=size(alphas,1);
        row=alpharow;
        if row >=2
            rest(row)=0;
        end
        rest(1)=sum(sig(t2index,2:alphaK+1).*wsval(t2index,1:alphaK),2);
        for ii=2:alphaK+1
            rest(ii)=sig(t2index,1).*wsval(t2index,ii-1);
        end
        rest(alphaK+2:2*alphaK+1)=sqrt(2)*sig(t2index,2:alphaK+1).*wsval(t2index,1:alphaK);
        begins=2*alphaK+2; ends=begins+alphaK*(alphaK-1)/2-1;
        for ii=begins:ends
            myk=find(alphas(ii,:)==1);
            rest(ii)=wsval(t2index,myk(1)).*sig(t2index,myk(2)+1)+wsval(t2index,myk(2)).*sig(t2index,myk(1)+1);
        end
        
%         rest(1)=0;
%         rest(2:k+1)=0;%sum(nsval(t2index,1:k).*msval(t2index,1:k));
%         rest(k+2:2*k+1)=1/sqrt(2)*nsval(t2index,1:k).*msval(t2index,1:k);
%         for ii=2*k+2:row
%             myk=find(betas(ii,:)==1);
%             rest(ii)=msval(t2index,myk(1))*nsval(t2index,myk(2))+...
%                 msval(t2index,myk(2))*nsval(t2index,myk(1));
%         end
%         for ii=row-3:row
%             rest(ii)=6*sum(msval(t2index,1:k).*nsval(t2index,1:k),2)...
%                 +24*msval(t2index,ii-row+4)*nsval(t2index,ii-row+4);
%         end
            
            
            
%         c=1; d=1;
%         betarow=size(betas,1); alpharow=size(alphas,1);
%         row=alpharow*betarow;
%         if row >=2
%             rest(row)=0;
%         end
%         rest(1)=-1/2*sum(sig(t2index,:).^2)...
%             +d*sum(sig(t2index,2:betarow).*(msval(t2index,1:betarow-1)));
%         rest(2:betarow)=-sig(t2index,2:betarow).*sig(t2index,1);
%         for k=2:alpharow
%             rest(betarow*(k-1)+1:k*betarow)=c*(sig(t2index,1:betarow)...
%                 *msval(t2index,k-1));
%         end
end
rest=rest';



